package com.hncc.bms.controller;

import java.util.List;

import com.ruoyi.common.constant.UserConstants;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.hncc.bms.domain.BmsSettlementCat;
import com.hncc.bms.service.IBmsSettlementCatService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import javax.annotation.Resource;

/**
 * 结算类别Controller
 * 
 * @author ruoyi
 * @date 2020-08-13
 */
@RestController
@RequestMapping("/bms/settlement_cat")
@Api(tags = "结算类别接口")
public class BmsSettlementCatController extends BaseController
{
    @Resource
    private IBmsSettlementCatService bmsSettlementCatService;

    /**
     * 查询结算类别列表
     */
    @ApiOperation(value = "条件分页查询结算类别",httpMethod = "GET")
    @PreAuthorize("@ss.hasPermi('bms:settlement_cat:list')")
    @GetMapping("/list")
    public TableDataInfo list(BmsSettlementCat bmsSettlementCat)
    {
        startPage();
        List<BmsSettlementCat> list = bmsSettlementCatService.selectBmsSettlementCatList(bmsSettlementCat);
        return getDataTable(list);
    }

    /**
     * 导出结算类别列表
     */
    @PreAuthorize("@ss.hasPermi('bms:settlement_cat:export')")
    @Log(title = "结算类别", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BmsSettlementCat bmsSettlementCat)
    {
        List<BmsSettlementCat> list = bmsSettlementCatService.selectBmsSettlementCatList(bmsSettlementCat);
        ExcelUtil<BmsSettlementCat> util = new ExcelUtil<BmsSettlementCat>(BmsSettlementCat.class);
        return util.exportExcel(list, "settlement_cat");
    }

    /**
     * 获取结算类别详细信息
     */
    @ApiOperation(value = "根据id获取结算类别详细信息",httpMethod = "GET",
            notes = "根据id查询结算类别")
    @ApiImplicitParam(paramType = "path",name = "id",value = "结算类别id",dataType = "Long",required = true)
    @PreAuthorize("@ss.hasPermi('bms:settlement_cat:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(bmsSettlementCatService.selectBmsSettlementCatById(id));
    }

    /**
     * 新增结算类别
     */
    @ApiOperation(value = "新增",httpMethod = "POST", notes = "新增结算类别")
    @ApiImplicitParam(name = "bmsSettlementCat", value = "新增结算类别", dataType = "BmsSettlementCat")
    @PreAuthorize("@ss.hasPermi('bms:settlement_cat:add')")
    @Log(title = "结算类别", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BmsSettlementCat bmsSettlementCat)
    {
        if(UserConstants.NOT_UNIQUE.equals(bmsSettlementCatService.checkUserNameUnique(bmsSettlementCat.getName(),bmsSettlementCat.getId()))){
            return AjaxResult.error("新增结算类别'" + bmsSettlementCat.getName() + "'失败，该决算类别已存在");
        }
        return toAjax(bmsSettlementCatService.insertBmsSettlementCat(bmsSettlementCat));
    }

    /**
     * 修改结算类别
     */
    @ApiOperation(value = "修改", httpMethod = "PUT", notes = "修改结算类别")
    @ApiImplicitParam(name = "bmsSettlementCat", value = "修改结算类别", dataType = "BmsSettlementCat")
    @PreAuthorize("@ss.hasPermi('bms:settlement_cat:edit')")
    @Log(title = "结算类别", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BmsSettlementCat bmsSettlementCat)
    {
        if(UserConstants.NOT_UNIQUE.equals(bmsSettlementCatService.checkUserNameUnique(bmsSettlementCat.getName(),bmsSettlementCat.getId()))){
            return AjaxResult.error("新增结算类别'" + bmsSettlementCat.getName() + "'失败，该决算类别已存在");
        }
        return toAjax(bmsSettlementCatService.updateBmsSettlementCat(bmsSettlementCat));
    }

    /**
     * 删除结算类别
     */
    @ApiOperation(value = "批量删除", httpMethod = "DELETE", notes = "根据ids删除结算类别")
    @ApiImplicitParam(paramType = "path",name = "ids",value = "结算类别id",dataType = "Long[]",required = true)
    @PreAuthorize("@ss.hasPermi('bms:settlement_cat:remove')")
    @Log(title = "结算类别", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bmsSettlementCatService.deleteBmsSettlementCatByIds(ids));
    }
}
